<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>
<!--begin-->
<div class="section">
    <div class="section-title">Báo Cáo Tình Hình Phát Hành Báo Tại Khu Vực Quản Lý</div>
    <div class="right">
        <!--<a class="button print" href="">In</a>-->
        <a class="button exit" href="?route=deliman/home">Đóng</a>
    </div>
    <div class="clearer">&nbsp;</div>
    
    <div class="section-content padding1">  
    	<div>  	
            <form>
                <table>
                    <thead>
                        <tr class="left">
							<script language="javascript">
                            $(function() {
                            $("#tungay").datepicker({
                            changeMonth: true,
                            changeYear: true,
                            dateFormat: 'dd-mm-yy'
                            });
                            $("#denngay").datepicker({
                            changeMonth: true,
                            changeYear: true,
                            dateFormat: 'dd-mm-yy'
                            });
                            });
                            </script>
                            <td><label>Ngày phát hành: từ</label></td>
                            <td><input type="text" class="text" id="tungay" name="tungay" /></td>
                            <td><label>đến:</label></td>
                            <td><input type="text" class="text" id="denngay" name="denngay" /></td>
                        </tr>
                        <tr class="clearer"><td></td></tr>
                        <tr class="left">
                            <td><label>Loại báo:</label></td>
                            <td>
                                <select name="loaibaoid" id="loaibaoid">
                                    <?php 
                                    foreach($dsloaibao as $loaibao)
                                    { 
                                    ?>
                                        <option value="<?php echo $loaibao['loaibaoid']?>">
                                        <?php echo $loaibao['tenloaibao']?>
                                        </option>
                                    <?php 
                                    }
                                    ?>
                                </select>
                            </td>
                            <td><label>Kỳ báo:</label></td>
                            <td>
                                <select name="kybaoid" id="kybaoid">
                                	<?php echo $cmbkybao?>
                                </select>
                            </td>
                        	<td><a class="button-other search" onClick="searchForm()">Tìm kiếm</a></td>
                        </tr>
                    </thead>
                </table>
            </form>  
            
        	<form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">     
                <div class="khuvuc treeindex">
                    <link href="<?php echo DIR_VIEW?>css/jquery.treeTable.css" rel="stylesheet" type="text/css" />
                    <script type="text/javascript" src="<?php echo DIR_VIEW?>js/jquery.treeTable.js"></script>
                    <script type="text/javascript">
						$(document).ready(function() {
						// TODO Fix issue with multiple treeTables on one page, each with different options
						// Moving the #example3 treeeTable call down will break other treeTables that are expandable...
							$(".example").treeTable();
						});
                    
                    </script>
                    <table class="example data-table table-form">
                        <thead>
                            <tr class="tr-head">
                                <th>Khu vực</th>
                                <th width="15%">Chỉ tiêu</th>
                                <th width="15%">Thực giao</th>
                                <th width="15%">Tỷ lệ</th>
                            </tr>
                        </thead>                    
                        <tbody>
                            <!- Neu $phieuphanphoiid cua ky bao chua duoc lap thi ko cho hien TREE: KHU VUC ->
                            <?php  
                                if(isset($phieuphanphoiid))
                                {
                                    foreach($khuvucs as $khuvuc)
                                    {
                            ?>
                            <tr  id="<?php echo $khuvuc['eid']?>" class="<?php echo $khuvuc['class']?>">
                                <td>
                                    <?php echo $khuvuc['tab']?>
                                        <!--<input  type="hidden" name="khuvucid[<?php echo $khuvuc['khuvucid']?>]" 
                                        value="<?php echo $khuvuc['khuvucid']?>" >
                                        <input type="hidden" name="id[<?php echo $khuvuc['khuvucid']?>]" 
                                        value="<?php echo $khuvuc['ctphanphoi']['id']?>" />-->
                                    <?php echo $khuvuc['tenkhuvuc']?>
                                </td>
                                <td class="number">
                                    <?php 
                                        $chitieu = 0;
                                        if(isset($khuvuc['ctphanphoi']['chitieu'])){
                                        	$chitieu = $khuvuc['ctphanphoi']['chitieu'];
                                        }
                                        else{
                                        	$chitieu = 0;
                                        }
                                        echo $this->string->numberFormate($chitieu);
                                    ?>
                                </td>
                                <td class="number">
                                	<?php echo $this->string->numberFormate($khuvuc['thucgiao']) ?>
                                </td>
                                <td class="number">
                                    <?php  
                                        $tyle = 0;
                                        if((int)$chitieu != 0){
                                            $tyle = (int)$khuvuc['thucgiao']/(int)$chitieu;
                                            $tyle *= 100;
                                        }
                                        echo $tyle."%";
                                    ?>
                                </td>
                            </tr>
                                <?php
                                	}                       
                                }
                                else{
                                ?>
                            <tr class="tr-head">
                                <td width="15%" colspan="4">
                                	<b>Bạn chưa chọn kỳ báo cần xem hoặc kỳ báo bạn chọn chưa được phân phối..</b>
                                </td>
                            </tr>
                                <?php
                                }
                                ?>    
                        </tbody>              	    
                    </table>                
                </div> 
            </form>                
        </div>
        <div class="clearer">&nbsp;</div>
	</div>
    
    <div class="section-bottom"></div>
</div>
<!--end-->

<script language="javascript">
	$("#loaibaoid").change(function(){
		$('#kybaoid').load('?route=deliman/baocaotinhhinhphathanhbaotaikhuvucquanly/getKyBao&loaibaoid='+$(this).val()+'&tungay='+$('#tungay').val()+'&denngay='+$('#denngay').val(), 
		function()
		{
			$('#kybaoid').val("<?php echo $_GET['kybaoid']?>");
		});
	});
	$('#loaibaoid').val("<?php echo $_GET['loaibaoid']?>");
	$("#loaibaoid").change();
	

function searchForm()
{
	var url =  "?route=deliman/baocaotinhhinhphathanhbaotaikhuvucquanly";
	if($("#loaibaoid").val() != "")
		url += "&loaibaoid="+ $("#loaibaoid").val();	
	if($("#kybaoid").val() != "")
		url += "&kybaoid="+ $("#kybaoid").val();
	if($("#tungay").val() != "")
		url += "&tungay="+ $("#tungay").val();
	if($("#denngay").val() != "")
		url += "&denngay="+ $("#denngay").val();	
	window.location = url;
}

$("#tungay").val("<?php echo $_GET['tungay']?>");
$("#denngay").val("<?php echo $_GET['denngay']?>");
</script>